﻿using Microsoft.Phone.Maps.Controls;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Device.Location;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace WindowsPhone_Map_TTTN
{
    class MapView
    {
       
        public MapView()
        {
            _homLayer = new MapLayer();
            _map = MFactory.getMap();
            
        }
        public static MapView  getInstance()
        {
           if(_instance==null) _instance = new MapView();
            return _instance;
        }
        public int addHomePoint(double x, double y){
            this._homLayer.Add(write_point(x,y, (int) _map.ZoomLevel));
            _map.Layers.Add(_homLayer);
            return 0;
        }
        private static MapView _instance;
        private Map _map;
        private MapLayer _homLayer;
        private MapOverlay write_point(double x, double y, int zoomlevel)
        {
            //Creating a Grid element.

            Grid MyGrid = new Grid();
            MyGrid.RowDefinitions.Add(new RowDefinition());
            MyGrid.RowDefinitions.Add(new RowDefinition());
            MyGrid.Background = new SolidColorBrush(Colors.Transparent);

            //Creating a Rectangle
            Rectangle MyRectangle = new Rectangle();
            MyRectangle.Fill = new SolidColorBrush(Colors.Red);
            MyRectangle.Height = zoomlevel;
            MyRectangle.Width = zoomlevel;
            MyRectangle.SetValue(Grid.RowProperty, 0);
            MyRectangle.SetValue(Grid.ColumnProperty, 0);
            MyGrid.Children.Add(MyRectangle);

            MapOverlay MyOverlay = new MapOverlay();
            MyOverlay.Content = MyGrid;
            MyOverlay.GeoCoordinate = new GeoCoordinate(x, y);
            MyOverlay.PositionOrigin = new Point(0, 0.5);
            return MyOverlay;
        }
    }
}
